package luj.tool.jnproxyan.framework.lujnet.receive;

import io.netty.buffer.ByteBuf;
import luj.net.api.server.FrameDataReceiver;
import luj.tool.jnproxyan.framework.lujnet.ConnState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
final class Recv43RequestAddrDomainLen implements FrameDataReceiver {

  @Override
  public Result receive(Context ctx) throws Exception {
    ByteBuf frameBuf = ctx.getLastFrame();
    ConnState connState = ctx.getConnectionState();

    int addrLen = frameBuf.readByte();
    connState.setDomainLen(addrLen);

    return ctx.then()
        .waitBytes(addrLen)
        .nextReceiver(_receiveDomain);
  }

  @Autowired
  private Recv44RequestAddrDomain _receiveDomain;
}
